package com.wy.controller;

import com.wy.bean.User;
import com.wy.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 进入登录页面
     */
    @RequestMapping("tologin")
    public String tologin(){
        return "login";
    }

    /**
     * 登录方法
     * @return
     */
    @RequestMapping("login")
    @ResponseBody
    public boolean login(User user, HttpSession httpSession){
        User user1 = userService.getByLoginNameAndpwd(user);
        if(user1 == null){
            return false;
        }else{
            httpSession.setAttribute("user",user1);
            return true;
        }
    }

    /**
     * 进入登录页面--登录成功以后才能访问
     */
    @RequestMapping("list")
    public String list(){
        return "list";
    }

    /**
     * 注销
     */
    @RequestMapping("logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "login";
    }
}
